/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */

/*
 * TimeLinePanel.java
 * <p/>
 * Created on Jul 28, 2011, 8:57:33 PM
 */
package jme3timeline;

import sg.atom.timeline.model.cine.creator.RandomDemoModelCreator;
import de.jaret.timebars.hierarchy.SumRenderer;
import de.jaret.timebars.pdi.ControlPanel1;
import de.jaret.util.ui.timebars.mod.DefaultIntervalModificator;
import de.jaret.util.ui.timebars.model.AddingTimeBarRowModel;
import de.jaret.util.ui.timebars.model.HierarchicalTimeBarModel;
import de.jaret.util.ui.timebars.model.TimeBarNode;
import de.jaret.util.ui.timebars.swing.TimeBarViewer;
import de.jaret.util.ui.timebars.swing.renderer.DefaultHierarchyRenderer;
import de.jaret.util.ui.timebars.swing.renderer.DefaultRelationRenderer;
import de.jaret.util.ui.timebars.swing.renderer.DefaultTitleRenderer;
import javax.swing.BoxLayout;

/**
 *
 * @author hungcuong
 */
public class TimeLinePanel extends javax.swing.JPanel {

    /**
     * Creates new form TimeLinePanel
     */
    public TimeLinePanel() {
        initComponents();
        initTestPanel();
    }

    void initTestPanel() {
        // create the model
        HierarchicalTimeBarModel model = RandomDemoModelCreator.createModel(2, 5);

        TimeBarViewer _tbv = new TimeBarViewer();
        _tbv.setName("Hierarchy");
        _tbv.setModel(model);
        _tbv.setTimeScalePosition(TimeBarViewer.TIMESCALE_POSITION_TOP);
        _tbv.setHierarchyRenderer(new DefaultHierarchyRenderer());
        _tbv.setHierarchyWidth(100);
        _tbv.setYAxisWidth(100);
        // allow all interval modifications
        _tbv.addIntervalModificator(new DefaultIntervalModificator());

        // register additional renderer for the erged intervals of the addind row model
        _tbv.registerTimeBarRenderer(AddingTimeBarRowModel.MergedInterval.class, new SumRenderer());

        // set the default title renderer
        _tbv.setTitleRenderer(new DefaultTitleRenderer());

        // setup relation rendering
        _tbv.setRelationRenderer(new DefaultRelationRenderer());


        /*
        // add a marker
        TimeBarMarkerImpl tm = new TimeBarMarkerImpl(true, new JaretDate().advanceDays(1));
        tm.setDescription("Timebarmarker");
        _tbv.addMarker(tm);
         */
        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
        this.add(_tbv);

        // expand all nodes
        TimeBarNode root = model.getRootNode();
        _tbv.getHierarchicalViewState().setExpandedRecursive(root, true);



        // add the control panel
        ControlPanel1 cp = new ControlPanel1(_tbv, null, true);
        this.add(cp);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
